import axios from 'axios';

axios.defaults.baseURL = 'http://192.168.3.84:80';
// axios.defaults.baseURL = 'https://jxxz.zhjd.zjhongsen.cn';

axios.defaults.headers['Content-Type'] = 'application/json';

let xwindow: any = window;
axios.defaults.headers['Authorization'] = xwindow.localStorage.getItem("sessionId");
// 请求超时的时间限制
axios.defaults.timeout = 50000;
// 开始设置请求 发起的拦截处理
axios.interceptors.request.use((config: any) => {
  return config;
}, (error: any) => {
  return Promise.reject(error);
});

// 请求到结果的拦截处理
axios.interceptors.response.use((config: any) => {
  if (config.data.status == 403) {
    // 未登陆授权返回到登录页面
    // window.location.href = axios.defaults.baseURL+`/`
    window.location.href = "http://localhost:3006"+`/` //上线替换

  }
  
  return config.data;
}, (error: any) => {
  // 当为500的时候是直接走的这里
  return Promise.reject(error);
});



// ================退出登录===============
export const outLogin = async () => {
  // return await axios.post('/log', {})
}


// //================公共接口开始===============
// 1、获取oss
export const commonOssGet = async (params) => {
  return await axios.post('/api/micro/oss_get_param.json', params)
}
//获取文章列表
export const homeIndex = async (params) => {
  return await axios.post('/api/micro/article_get_list.json', params)
}
//登录
export const login = async (params) => {
  return await axios.post('/api/admin/admin_login.json', params)
}

//登录
export const getMemberList = async (params) => {
    return await axios.post('/api/admin/member_get_list.json', params)
}

//获取街道列表
export const getStreetList = async (params) => {
    return await axios.post('/api/admin/street_get_list.json', params)
}
//获取网格列表
export const getGridList = async (params) => {
  return await axios.post('/api/admin/grid_get_list.json', params)
}

// 新增网格
export const addGrid = async (params) => {
  return await axios.post('/api/admin/grid_add.json', params)
}

// 获取社区名称
export const getCommunityList = async (params) => {
  return await axios.post('/api/admin/community_get_list.json', params)
}

// 获取部门
export const getDepartmentList = async (params) => {
    return await axios.post('/api/admin/department_get_list.json', params)
  }
// 获取小区名称
export const getComplexList = async (params) => {
  return await axios.post('/api/admin/complex_get_list.json', params)
}
// 微检查列表
export const getCheckList = async (params) => {
  return await axios.post('/api/admin/check_get_list.json', params)
}
// 文章列表
export const getArticleList = async (params) => {
  return await axios.post('/api/admin/article_get_list.json', params)
}
// 微民情列表
export const getMinqingList = async (params) => {
  return await axios.post('/api/admin/minqing_get_list.json', params)
}

// 微宣教
export const getPaeClassList = async (params) => {
    return await axios.post('/api/admin/pae_get_class_list.json', params)
}

// 微宣教
export const addPae = async (params) => {
    return await axios.post('/api/admin/pae_add.json', params)
}

// 新增微宣教类别
export const addPaeClass = async (params) => {
    return await axios.post('/api/admin/pae_class_add.json', params)
}

// 微宣教
export const getPaeList = async (params) => {
  return await axios.post('/api/admin/pae_get_list.json', params)
}
// 新增用户
export const addUser = async (params) => {
  return await axios.post('/api/admin/admin_add.json', params)
}
// 新增社区
export const addCommunity = async (params) => {
  return await axios.post('/api/admin/community_add.json', params)
}

// 新增文章
export const addArticle = async (params) => {
  return await axios.post('/api/admin/article_add.json', params)
}
//错误方法
export const xerror = async (params) => {
  let name:any = '';
  let value:any = '';
  let error:any = {
		'0':'操作成功！',
    '2':'内部错误', 
    '3':'sort不合法', 
    '4':'range不合法', 
    '5':'filter不合法', 
    '10':'id不合法', 
    '11':'类型错误', 
    '100':'用户名错误',
    '101':'密码错误',
    '403': '无权限'
  }
  for ( var key in error) {			
    //通过遍历对象属性的方法，遍历键值对，获得key，然后通过 对象[key]获得对应的值			
    if(key == params){
      value = error[key];
    }
  } 
  return value
}